package org.csu.mypetstore.persistence;




import java.sql.*;

public class DBUtil {
    private static String driver = "com.mysql.cj.jdbc.Driver";
    private static String url = "jdbc:mysql://127.0.0.1:3306/mypetstore?serverTimezone=GMT%2B8";
    private static String username = "root";
    private static String password = "root";

    public static Connection getConnetion() throws Exception {
        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }


    public static void closeConnection(Connection connection) throws SQLException {
        if (connection != null){
            connection.close();
        }
    }

    public  static  void closeStatement(Statement statement) throws SQLException {
        if (statement != null){
            statement.close();
        }
    }

    public  static  void closePreparedStatement(PreparedStatement statement) throws SQLException {
        if (statement != null){
            statement.close();
        }
    }

    public  static  void closeResultSet(ResultSet resultSet) throws SQLException {
        if (resultSet != null){
            resultSet.close();
        }
    }
}
